package com.ontheroad.controller;

import cn.modoumama.page.GridDataModel;
import com.ontheroad.core.util.JSONUtils;
import com.ontheroad.core.web.BaseController;
import com.ontheroad.path.service.PathSysService;
import com.ontheroad.system.service.SysDictService;
import com.ontheroad.user.model.UserModel;
import com.ontheroad.user.service.SystemUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static com.ontheroad.core.util.SysInitConfig.getInstance;

/**
 * Created by kedong on 2017/8/24 0024.
 */
@Controller
@RequestMapping("syspath")
public class PathSysController extends BaseController {
    private Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private PathSysService pathSysService;

    @RequestMapping("list")
    public String list(HttpServletRequest request) {
        return "path/sys/list";
    }

    @RequestMapping("getData")
    @ResponseBody
    public GridDataModel getData(HttpServletRequest request) {
        return getGridData(request, pathSysService);
    }


    @RequestMapping(value = "delete")
    public void delete(HttpServletRequest request, PrintWriter out) {
        log.debug("method: delete() ");
        String msg = "操作成功";
        boolean result = true;
        try {
            String ids = request.getParameter("ids");
            String[] pathIds = ids.split(",");
            for (String id : pathIds) {
                pathSysService.removeById(Long.parseLong(id));
            }
        } catch (Exception e) {
            msg = "系统发生异常！";
            result = false;
        }
        ajaxJsonResponse(out, result, msg);
    }

}
